import sys
from PySide2.QtWidgets import QApplication, QWidget, QSlider, QHBoxLayout
from PySide2 import QtCore
class CustomSlider(QWidget):
    def __init__(self):
        super().__init__()

        self.init_ui()

    def init_ui(self):
        layout = QHBoxLayout()

        slider = QSlider()
        slider.setOrientation(QtCore.Qt.Orientation.Horizontal)  # 设置为水平方向

        # 设置滑块的样式表
        slider.setStyleSheet('QSlider::handle:horizontal {'
                             '    background-color: #3498db;'
                             '    border: 1px solid #2980b9;'
                             '    width: 40px;'  # 设置滑块宽度
                             '    height: 20px;'  # 设置滑块高度
                             '    border-radius: 10px;'
                             '}'
                             'QSlider::groove:horizontal {'
                             '    background-color: #ecf0f1;'
                             '    border: 1px solid #bdc3c7;'
                             '    height: 20px;'  # 设置滑槽高度
                             '    border-radius: 10px;'
                             '}')

        layout.addWidget(slider)
        self.setLayout(layout)

        self.setWindowTitle('Custom Slider')
        self.setGeometry(100, 100, 300, 200)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = CustomSlider()
    window.show()
    sys.exit(app.exec_())
